package com.zbkj.dal.pojo.response;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zbkj.dal.entity.order.OrderRentSharedRecord;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 商户端订单详情响应对象
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "OrderMerchantDetailResponse对象", description = "商户端订单详情响应对象")
public class OrderAdminDetailResponse implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "订单号")
    private String orderNo;

    @ApiModelProperty(value = "用户id")
    private Integer uid;

    @ApiModelProperty(value = "订单商品总数")
    private Integer totalNum;

    @ApiModelProperty(value = "商品总价")
    private BigDecimal proTotalPrice;

    @ApiModelProperty(value = "邮费")
    private BigDecimal totalPostage;

    @ApiModelProperty(value = "订单总价")
    private BigDecimal totalPrice;

    @ApiModelProperty(value = "折后金额")
    private BigDecimal amount;

    @ApiModelProperty(value = "优惠券金额")
    private BigDecimal couponPrice;

    @ApiModelProperty(value = "使用积分")
    private Integer useIntegral;

    @ApiModelProperty(value = "积分抵扣金额")
    private BigDecimal integralPrice;

    @ApiModelProperty(value = "实际支付金额")
    private BigDecimal payPrice;

    @ApiModelProperty(value = "支付邮费")
    private BigDecimal payPostage;

    // 目前只有一个商品
    @ApiModelProperty(value = "商品单价")
    private BigDecimal productPrice;

    @ApiModelProperty(value = "数量/天数")
    private Integer num;

    @ApiModelProperty(value = "支付状态")
    private Boolean paid;

    @ApiModelProperty(value = "支付时间")
    private Date payTime;

    @ApiModelProperty(value = "支付方式:weixin,alipay,yue")
    private String payType;

    @ApiModelProperty(value = "支付渠道：public-公众号,mini-小程序，h5-网页支付,yue-余额，wechatIos-微信Ios，wechatAndroid-微信Android,alipay-支付宝，alipayApp-支付宝App")
    private String payChannel;

    @ApiModelProperty(value = "支付类型", example = "微信支付")
    private String payTypeDesc;

    @ApiModelProperty(value = "订单状态（0：待支付，1：待发货,2：部分发货， 3：待核销，4：待收货,5：已收货,6：已完成，9：已取消）")
    private Integer status;

    @ApiModelProperty(value = "退款状态：0 未退款 1 申请中 2 退款中 3 已退款")
    private Integer refundStatus;

    @ApiModelProperty(value = "取消状态：0-未取消，1-系统取消，2-用户取消")
    private Integer cancelStatus;

    @ApiModelProperty(value = "用户是否删除")
    private Boolean isUserDel;

    @ApiModelProperty(value = "赠送积分")
    private Integer gainIntegral;

    @ApiModelProperty(value = "商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号")
    private String outTradeNo;

    @ApiModelProperty(value = "订单类型:0-普通订单，1-视频号订单")
    private Integer type;

    @ApiModelProperty(value = "订单等级:0-主订单，1-商户订单，2-商户子订单")
    private Integer level;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "收货人姓名")
    private String realName;

    @ApiModelProperty(value = "收货人电话")
    private String userPhone;

    @ApiModelProperty(value = "收货详细地址")
    private String userAddress;

    @ApiModelProperty(value = "用户备注")
    private String userRemark;

    @ApiModelProperty(value = "商户备注")
    private String merchantRemark;

    @ApiModelProperty(value = "配送方式 1=快递 ，2=门店自提")
    private Integer shippingType;

    @ApiModelProperty(value = "一级返佣金额")
    private BigDecimal firstBrokerage;

    @ApiModelProperty(value = "二级返佣金额")
    private BigDecimal secondBrokerage;

    @ApiModelProperty(value = "平台手续费")
    private BigDecimal commissionCharge;

    @ApiModelProperty(value = "核销码")
    private String verifyCode;

    @ApiModelProperty(value = "发货类型：express-快递，fictitious：虚拟发货")
    private String deliveryType;

    @ApiModelProperty(value = "快递名称", example = "顺丰快递")
    private String expressName;

    @ApiModelProperty(value = "快递单号", example = "SF0001")
    private String expressNumber;

    @ApiModelProperty(value = "是否拆分发货")
    private Boolean isSplitDelivery;

    @ApiModelProperty(value = "核销员id")
    private Integer clerkId;

    // 以下为自定义添加部分

    @ApiModelProperty(value = "用户昵称")
    private String nikeName;

    @ApiModelProperty(value = "用户手机号")
    private String phone;

    @ApiModelProperty(value = "用户是否注销")
    private Boolean isLogoff;

    @ApiModelProperty(value = "核销员名称")
    private String clerkName;

    @ApiModelProperty(value = "订单商品详情")
    List<OrderInfoFrontDataResponse> orderDetailList;


    @ApiModelProperty(value = "商户优惠券金额")
    private BigDecimal merCouponPrice;

    @ApiModelProperty(value = "平台优惠券金额")
    private BigDecimal platCouponPrice;

    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    @ApiModelProperty(value = "订单完成时间", example = "2024-04-20 00:00:00")
    private LocalDateTime finishTime;

    @ApiModelProperty(value = "承享信息")
    private RentInfo rentInfo;

    @ApiModelProperty(value = "归还信息")
    private ReturnInfo returnInfo;

    @ApiModelProperty(value = "支付信息")
    private List<PayInfo> payInfos;

    @ApiModelProperty(value = "是否存在归还")
    private Boolean alreadyReturn;

    @Data
    @ApiModel
    public static class PayInfo {
        @ApiModelProperty(value = "支付类型", example = "在线支付")
        private String payForm;

        @ApiModelProperty(value = "价格", example = "10.00")
        private BigDecimal price;

        @ApiModelProperty(value = "天数/数量", example = "2")
        private Integer num;

        @ApiModelProperty(value = "订单价格", example = "100.00")
        private BigDecimal orderAmount;

        @ApiModelProperty(value = "优惠金额", example = "0.00")
        private BigDecimal couponAmount;

        @ApiModelProperty(value = "订单折后金额", example = "100.00")
        private BigDecimal realAmount;

        @ApiModelProperty(value = "运费", example = "0.00")
        private BigDecimal freight;

        @ApiModelProperty(value = "雅识抵扣金额", example = "10.00")
        private BigDecimal balanceAmount;

        @ApiModelProperty(value = "实际支付金额", example = "90.00")
        private BigDecimal payAmount;

        @ApiModelProperty(value = "支付方式", example = "weixin")
        private String payChannel;

        @ApiModelProperty(value = "支付方式", example = "微信支付")
        private String payChannelDesc;

    }

    @Data
    @ApiModel
    public static class ReturnInfo {

        @ApiModelProperty(value = "归还方式")
        private String returnType;

        @ApiModelProperty(value = "预约归还时间")
        private LocalDateTime reservationReturnTime;

        @ApiModelProperty(value = "实际签收时间")
        private LocalDateTime receiptTime;

        @ApiModelProperty(value = "归还店铺")
        private String receiptShop;

        @ApiModelProperty(value = "归还额度")
        private BigDecimal returnQuota;

        @ApiModelProperty(value = "归还物流信息")
        private String returnLogisticsInfo;
    }

    @Data
    @ApiModel
    public static class RentInfo {

        @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
        @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
        @ApiModelProperty(value = "承享开始时间", example = "2024-04-20 00:00:00")
        private LocalDateTime rentStartTime;

        @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
        @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
        @ApiModelProperty(value = "承享结束时间", example = "2024-04-20 00:00:00")
        private LocalDateTime rentEndTime;

        @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
        @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
        @ApiModelProperty(value = "是否超时", example = "2024-04-20 00:00:00")
        private Boolean expire;

        @ApiModelProperty(value = "是否宽容期", example = "true")
        private Boolean tolerant;

        @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
        @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
        @ApiModelProperty(value = "宽容期限", example = "2024-04-20 00:00:00")
        private LocalDateTime tolerantTime;

    }

    public void setRent(OrderRentSharedRecord orderRentSharedRecord) {
        if (Objects.nonNull(orderRentSharedRecord)) {
            RentInfo info = new RentInfo();
            info.setRentStartTime(orderRentSharedRecord.getRentStartDate());
            info.setRentEndTime(orderRentSharedRecord.getRentEndDate());
            info.setExpire(orderRentSharedRecord.getStatus() == 9);
            info.setTolerant(orderRentSharedRecord.getStatus() == 9 || orderRentSharedRecord.getStatus() == 3);
            info.setTolerantTime(orderRentSharedRecord.getExpiredEndDate());
            this.rentInfo = info;
        }
    }

}
